
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加文章</title>
    {include file="include/top"}
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <select name="status">
                        <option value="1">正常</option>
                        <option value="-1">删除</option>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">分类</label>
                <div class="layui-input-inline">
                    {include file="include/cid"}
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" placeholder="请填入..." autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
            </div>
        </div>
        <div class="layui-card-header layuiadmin-card-header-auto">
            <button type="button" class="layui-btn" id="test-upload-type1" data-imgid="addfood"><i class="layui-icon"></i>添加</button>
        </div>
        <table class="layui-table" lay-data="{height:0, url:'/goods/goodsList', page:true, id:'idTest'}" lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{field:'id',  sort: true, fixed: true,width:80}">ID</th>
                <th lay-data="{field:'title'}">标题</th>
                <th lay-data="{field:'cid'}">类型</th>
                <th lay-data="{field:'addtime'}">添加</th>
                <th lay-data="{field:'status',templet:function(d){
                    if(d.status==1)
                    return '正常';
                    else
                    return '删除';
                    }
                }
                ">状态</th>
                <th lay-data="{fixed: 'right',  align:'center', toolbar: '#barDemo',width:80}"></th>
            </tr>
            </thead>
        </table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edituser">修改</a>
        </script>
    </div>
</div>
{include file="include/js"}
<script>
    var pathid=0;
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'contlist', 'table'], function(){
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;
        var pathid=0;
        var id=0;
        $("#test-upload-type1").click(function (){
            id=0
            editGood()
        })
        function editGood(){
            layer.open({
                type: 2
                ,title: '添加或修改'
                ,content: 'goodsAdd?id='+id
                ,btn: ['确定', '取消']
                ,area: ['80%', '80%']
                ,yes: function(index, layero){
                    layer.confirm('是否确定操作?', {icon: 3, title:'提示'}, function(index){
                        //do something
                        var $data={};
                        var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags");
                        $data.cid = othis.find('select[name="cid"]').val()
                        $data.supplier = othis.find('select[name="supplier"]').val()
                        $data.auction = othis.find('select[name="auction"]').val()
                        $data.status = othis.find('select[name="status"]').val()
                        $data.title = othis.find('input[name="title"]').val()
                        $data.parameter = othis.find('input[name="parameter"]').val()
                        $data.numbers = othis.find('input[name="numbers"]').val()
                        $data.price = othis.find('input[name="price"]').val()
                        $data.price2 = othis.find('input[name="price2"]').val()
                        $data.price3 = othis.find('input[name="price3"]').val()
                        $data.percent = othis.find('input[name="percent"]').val()
                        $data.days = othis.find('input[name="days"]').val()
                        $data.startDate = othis.find('input[name="startDate"]').val()
                        $data.img = othis.find('input[name="img"]').val()
                        $data.sortnum = othis.find('input[name="sortnum"]').val()
                        $data.files = othis.find('input[name="files"]').val()
                        $data.content = othis.find('#LAY_layedit_2').contents().find("body").html()
                        var temArr=[]
                        othis.find('input[name="rounds"]').each(function (){
                            var $obj = $(this)
                            if($obj[0].checked){
                                temArr.push($obj.data("id"))
                            }
                        })
                        $data.rounds = JSON.stringify(temArr)
                        $.post("/goods/goodsSave?id="+id,$data,function (re) {
                            layer.msg(re.msg);
                            if(re.code == 0){
                                setTimeout(function () {
                                    location.reload();
                                },2000);
                            }
                        },'json');
                        layer.close(index);
                    });
                }
            });
        }
        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('idTest', {
                where: field
            });
        });
        $('.layui-btn.layuiadmin-btn-tags').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'admin'){

            } else if(obj.event === 'edit'){

            } else if(obj.event === 'quyu'){

            } else if(obj.event === 'edituser'){
                id=data.id;
                editGood()
            }
        });
    });
</script>

</body>
</html>
